$(function() {
	initTabs();
});

function dialog() {
	
}

function initTabs() {
	$( "#tabs" ).tabs();
	$( "#tabs" ).tabs({
	   select: function( event, ui ) {
			ui.panel.innerHTML='slkl';
			var name = ui.tab.innerHTML;
			var status;
			ui.panel.innerHTML = '<div align=center><font color=red><b><h1>加载数据中~~<h1></b></font></div>';
			
			if( name == "等待买家付款" ) {
				status = 'WAIT_BUYER_PAY';
			} else if( name == "等待卖家发货" ) {
				status = 'WAIT_SELLER_SEND_GOODS';
			} else {
				status = 'WAIT_BUYER_CONFIRM_GOODS';
			}
			
			$.get("trade.jsp", { status: status }, function(data) {
	 			ui.panel.innerHTML = data;
	 			$( "input:button, input:submit" ).button();
	 		});
		}
	});
	$( "#tabs" ).tabs( "select", 1 );
}

function selectAll() {
	var b = $("#selectAllCheckbox").attr("checked");     //读取所有name为'chk_list'对象的状态（是否选中）
	if(b != "checked") {
		$("input[name='tid']").attr("checked", false); 
	} else {
		$("input[name='tid']").attr("checked",true); 
	}
}

function confirms(str) {
	var form = $('#form');
	
	var xx = window.confirm(str);
	if(!xx) {
		form.attr('action', '');
	}
}

function collapseAll(num, vv) {
	var i = 0;
	var collapseAllOrder = $("#collapseAllOrder");
	
	for(i; i < num; i++) {
		expand(i, vv);
	}
	
	if(vv) {
		collapseAllOrder.attr("onclick", "collapseAll(" + num + ", false)");
		collapseAllOrder.attr("value", "展开全部");
	} else {
		collapseAllOrder.attr("onclick", "collapseAll(" + num + ", true)");
		collapseAllOrder.attr("value", "折叠全部");
	}
}

function showPic(img) {
	var size = getImgSize(img);
	
	var width= size.width + 20;
	var height= size.height + 20;
	
    var top = (window.screen.height - size.height) / 2;
    var left = (window.screen.width - size.width) / 2;
    
    var picUrl = img.src;
    
    window.showModalDialog('showPic.html', picUrl, "dialogWidth: " + width + "px; dialogHeight: " + height + "px; dialogLeft:" + left + "px; dialogTop:" + top + "px  center: yes; resizable: no; scroll: no; status: no; location: no");
}

function getImgSize(img){ 
  var image=new Image(); 
  image.src = img.src;
  
  var size = new Object();
  size.width = image.width;
  size.height = image.height;
  
  return size;
 }

function openUrl(tid,buyer_name) {
	var width = 500;
	var height = 300;
	
	var top = (window.screen.height - height) / 2;
    var left = (window.screen.width - width) / 2;
    
	window.showModalDialog('send.jsp?tid=' + tid + '&buyer_name=' + buyer_name, window, "dialogWidth: " + width + "px; dialogHeight: " + height + "px; dialogLeft:" + left + "px; dialogTop:" + top + "px  center: yes; toolbar:no;resizable: no;scrollbars:no status: no; location: no");
	//window.location.reload(true);
}

function print(tid) {
	
	$( "#dialog-confirm" ).dialog({
		resizable: false,
		height:140,
		modal: true,
		buttons: {
			"确认": function() {
				$.get("./servlet/PrintExpress", { tid: tid, print_flag: true});	
				$( this ).dialog( "close" );
			},
			Cancel: function() {
				$( this ).dialog( "close" );
			}
		}
	});
}

function searchLog(tid) {
	var width= 800;
	var height= 600;
	
    var top = (window.screen.height - height) / 2;
    var left = (window.screen.width - width) / 2;
    
    window.showModalDialog('logistics.jsp?tid=' + tid, null, "dialogWidth: " + width + "px; dialogHeight: " + height + "px; dialogLeft:" + left + "px; dialogTop:" + top + "px  center: yes; resizable: no; status: no; location: no");
}

function expand(id, vv) {
	var item_name = 'item' + id;
	var button_id = 'button_' + id;
	var tr = $("tr[name='" + item_name + "']");
	var btn = $("#" + button_id);
	
	if(vv) {
		tr.attr("style", "display:none");
		btn.attr("value", "展开");
		btn.attr("onclick", "expand(" + id + ", false)");
	} else {
		tr.attr("style", "");
		btn.attr("value", "折叠");
		btn.attr("onclick", "expand(" + id + ", true)");
	}
}

